// https://leetcode.cn/problems/number-of-segments-in-a-string/
// Created by ade on 2022/8/5.
//
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class Solution {
public:
    int countSegments(string s) {
        stringstream ss;
        int count = 0;
        string tmp;
        ss << s;
        while (getline(ss, tmp, ' ')) {
            if(tmp != "")
                count++;
        }
        return count;
    }
};

int main() {
    Solution so;
    cout << so.countSegments("Hello, my name is John");
    return 0;
}